const Reqman = require('reqman');
const fs = require('fs-extra');

const req = new Reqman({
    baseUrl: "http://127.0.0.1:7011"
});

const categories = [{
    order: 0,
    name: "刺梨综合资讯",
    alias: "complex",
    title: "",
    keywords: "",
    description: ""
}, {
    order: 1,
    name: "刺梨果的功效",
    alias: "function",
    title: "",
    keywords: "",
    description: ""
}, {
    order: 2,
    name: "刺梨果与疾病",
    alias: "disease",
    title: "",
    keywords: "",
    description: ""
}, {
    order: 3,
    name: "刺梨果的吃法",
    alias: "eatmethod",
    title: "",
    keywords: "",
    description: ""
}, {
    order: 4,
    name: "刺梨果的加工",
    alias: "processing",
    title: "",
    keywords: "",
    description: ""
}]

//jscms网站安装配置文件
const CONFIG = {
    super: { //管理员账户配置
        nickname: "刺梨之家小编", //昵称
        email: '599193733@qq.com', //邮箱账户
        password: "cch599193733", //密码
        power: [ //权限，不建议修改此处
            'super',
        ],
        score: 999999 //积分，不建议修改此处
    },

    mongoose: {
        host: '127.0.0.1', //mongodb主机
        port: '27017', //mongodb端口
        dbname: 'cilihome', //mongodb集合名称
        username: '', //mongodb账号
        password: '' //mongodb密码
    },

    menu: [{
        order: 1,
        name: "微信小程序",
        alias: "trend",
        link: "/page/wechat.html",
        activeUrl: "", //高亮匹配
    }, {
        order: 2,
        name: "刺梨交流",
        alias: "trend",
        link: "/page/wechat.html",
        activeUrl: "", //高亮匹配
    }, {
        order: 3,
        name: "刺梨果指数",
        alias: "trend",
        link: "/page/trend.html",
        activeUrl: "@/page/trend.html", //高亮匹配
    }],

    fristArticle: {
        userEmail: "599193733@qq.com",
        categoryName: "刺梨综合资讯",
        type: 1,
        title: "刺梨是什么？带你全面了解什么是刺梨",
        keywords: ['刺梨是什么'],
        description: "黔中无闲草，处处是灵药，在中国西南贵州大山深处生长着这样一种珍贵的药用植物---刺梨，五百多年前李时珍的《本草纲目》卷八有收录记载。",
        mdContent: "黔中无闲草，处处是灵药，在中国西南贵州大山深处生长着这样一种珍贵的药用植物---刺梨，五百多年前李时珍的《本草纲目》卷八有收录记载。"
    },

    fristComment: {
        articleTitle: "刺梨是什么？带你全面了解什么是刺梨",
        authorUrl: "http://www.baidu.com/",
        authorEmail: "test@test.com",
        mdContent: "写的不错，让我对刺梨的了解又多了一些。"
    },

    domainBase: {
        //如果有多个域名请增加数组项
        domains: [{
            protocol: 'http', //网站协议
            host: 'www.jscms.com', //网站完整域名
            port: '80' //端口
        }, {
            protocol: 'http', //网站协议
            host: '127.0.0.1', //网站完整域名
            port: '8080' //端口
        }]
    },

    website: {
        title: "刺梨之家 - 中国刺梨资讯信息交流中心", //网站首页标题
        keywords: "", //网站首页关键字
        description: "", //网站首页描述
        
        separator: " - ", //标题分隔符
        subtitle: "刺梨之家", //子页副标题
        
        icp: "京ICP备00000000号", //中国网站备案号，如果没有可留空
        footHTML: "<p>© 2018 www.meicili.com All Rights Reserved. 刺梨之家 版权所有</p>", //底部html代码，可以写统计代码等。
        logo: "", //网站logo
        favicon: "", //网站图标
        about: "刺梨之家提供全面的刺梨资讯，稳定的刺梨价格指数供广大刺梨爱好者参考。", //关于网站/网站介绍，不限字符数量，一般显示在主题模版底部或者侧边栏
        //友情链接信息
        friendLinks: [{
            name: "百度",
            logo: "",
            url: "https//www.baidu.com/"
        }]
    }
}

/* --- 以下代码禁止修改 -- */

req
//插入域名相关配置信息base
.push(function() {
    return {
    method: "POST",
    url: '/api/config/install',
    data: {
        name: "域名信息",
        alias: "domainBase", //英文别名
        info: CONFIG.domainBase, //配置信息
    }
}})
//插入站点配置信息website
.push(function() {
    return {
    method: "POST",
    url: '/api/config/install',
    data: {
        name: "站点信息",
        alias: "website", //英文别名
        info: CONFIG.website, //配置信息
    }
}})
//初始化菜单菜单配置信息menu
.push(function() {
    return {
    method: "POST",
    url: '/api/config/install',
    data: {
        name: "菜单信息",
        alias: "menu", //英文别名
        info: CONFIG.menu, //配置信息
    }
}})
//初始化文章自增计数
.push(function() {
    return {
    method: "POST",
    url: '/api/config/install',
    data: {
        name: "自增计数",
        alias: "articleCount", //英文别名
        info: {
            num: 0
        }, //配置信息
    }
}})
//初始化标签列表
.push(function() {
    return {
    method: "POST",
    url: '/api/config/install',
    data: {
        name: "标签列表",
        alias: "tags", //英文别名
        info: [], //标签列表
    }
}})

//创建刺梨之家的网站分类
categories.forEach((cat)=>{
    req.push(function() {
        return {
        method: "POST",
        url: '/api/category/install',
        data: cat
    }})
})

req
//创建超级管理员操作
.push(function() {
    return {
    method: "POST",
    url: '/api/user/super',
    data: CONFIG.super
}})
//创建第一篇文章
.push(function() {
    return {
    method: "POST",
    url: '/api/article/install',
    data: CONFIG.fristArticle
}})
//创建第一个评论
.push(function() {
    return {
    method: "POST",
    url: '/api/comment/install',
    data: CONFIG.fristComment
}})
.do(function() {
    let userinfo = CONFIG.mongoose.username + ':' + CONFIG.mongoose.password + '@';
    if ( userinfo === ":@" ) {
        userinfo = "";
    }
    let tplJS = `'use strict';
module.exports = {
    client: {
        url: process.env.EGG_MONGODB_URL || 'mongodb://${userinfo}${CONFIG.mongoose.host}:${CONFIG.mongoose.port}/${CONFIG.mongoose.dbname}',
        options: {
            poolSize: 20,
            useNewUrlParser: true
        }
    }
}
`

fs.writeFileSync('../config/db.js', tplJS);

});

//修改程序配置信息
